﻿using IRepository;
using IServices;
using SqlSugarAndEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Core;
using Core.ReflectionHelper;
using Core.CommonModel;
using Core.AutoFac;

namespace Services
{
    public class DictionaryService : BaseService<sys_dictionary>, IDictionaryService, IAutoInject
    {
        private IDictionaryRepository dictionaryRepository;
        public DictionaryService(IDictionaryRepository dictionaryRepository):base(dictionaryRepository)
        {
            this.dictionaryRepository = dictionaryRepository;
        }

        public List<sys_dictionary> GetAllDictionaryNode()
        {
            var source = dictionaryRepository.GetInfoToDataTable(t => true);
            var list = ReflectionConvertHelper.ConvertDatatableToTreeList<sys_dictionary>(source, "ID", "ParentID");
            return list;
        }

        public ResponseModel GetChildrenNodeByParentID(decimal ParentId)
        {
            return GetInfo(t => t.ParentID == ParentId);
        }

        public ResponseModel GetLazyNode(decimal? ParentId, int page = 1, int limit = 1000)
        {
            return CreateResponseModel(dictionaryRepository.GetLazyNode, ParentId, page, limit);
        }
    }
}
